#pragma once
// -------------------------------------------------
// BlinKit - BlinKit Library
// -------------------------------------------------
//   File Name: web_page_host.h
// Description: WebPageHost Class
//      Author: Ziming Li
//     Created: 2022-05-02
// -------------------------------------------------
// Copyright (C) 2022 MingYang Software Technology.
// -------------------------------------------------

#ifndef BLINKIT_WEB_PAGE_HOST_H
#define BLINKIT_WEB_PAGE_HOST_H

#include "blinkit/blink/public/platform/web_cursor_info.h"
#include "blinkit/blink/public/platform/web_screen_info.h"
#include "blinkit/blink/public/web/web_context_menu_data.h"
#include "blinkit/ui/animation/animation_proxy.h"

namespace blink {
class WebLayerTreeView;
}

namespace BlinKit {

class LayerTreeHost;
class WebPage;

class WebPageHost : public AnimationProxy
{
public:
    static std::unique_ptr<WebPageHost> CreateForPagePopup(WebPage &page);
    virtual ~WebPageHost(void);

    WebLayerTreeView* GetLayerTreeView(void) const;
    WebPage* GetWebPage(void) const final { return m_page; }

    void Resize(const IntSize &size);
    virtual void SetWindowRect(const IntRect &rect) { ASSERT_NOT_REACHED(); }
    virtual void Show(void) { ASSERT_NOT_REACHED(); }

    virtual bool CanBeClosed(void) const;
    virtual void Close(void) = 0;
    
    virtual void ChangeTitle(const std::string &title) { ASSERT_NOT_REACHED(); }

    virtual void ShowContextMenu(const WebContextMenuData &data) { ASSERT_NOT_REACHED(); }
    virtual void ClearContextMenu(void) {}

    void SetToolTipText(const String &tooltipText, TextDirection dir, unsigned long cookie);

    virtual WebScreenInfo GetScreenInfo(void);

    virtual void UpdateCursor(const WebCursorInfo &cursorInfo) { ASSERT_NOT_REACHED(); }

protected:
    WebPageHost(WebPage *page);

    void AttachWebPage(WebPage *page)
    {
        ASSERT(nullptr != page);
        ASSERT(nullptr == m_page);
        m_page = page;
    }
private:
    virtual void ShowToolTip(const std::string &text, TextDirection dir, unsigned long cookie) = 0;
    virtual void HideTooltip(void) = 0;

    // AnimationProxy
    void Rasterize(void) final;

    WebPage *m_page;
    std::unique_ptr<LayerTreeHost> m_layerTreeHost;
};

} // namespace BlinKit

#endif // BLINKIT_WEB_PAGE_HOST_H
